package com.atguigu.c_designed.m3beheviorModel.b1TemplateMethod;

public class TemplateMethodClient {
    public static void main(String[] args) {
        Template template = new MilksoyBeans();
        template.execute();
        Template pureSoy = new PureSoyBeans();
        pureSoy.execute();
    }
}
abstract class Template{

    public final void execute(){
        //select
        select();
        //addFlavor
        if (hookMethod()){
            addFlavor();
        }
        //method3
        method3();
        //method4
        method4();
    }

    public boolean hookMethod(){
        return true;
    }

    private void method4() {
        System.out.println("调料和黄豆精心研磨成豆浆");
    }

    private void method3() {
        System.out.println("充分浸泡8小时。。");
    }

    protected abstract void addFlavor();

    private void select() {
        System.out.println("精心挑选上等黄豆");
    }
}

class MilksoyBeans extends Template{

    @Override
    protected void addFlavor() {
        System.out.println("添加北纬38°优质奶源");
    }

}

class PureSoyBeans extends Template{

    @Override
    protected void addFlavor() {
        System.out.println("添加北纬38°优质奶源");
    }

    @Override
    public boolean hookMethod() {
        return false;
    }
}